import BaseWidget from "../BaseWidget";


const {ccclass, property, menu} = cc._decorator;

@ccclass
@menu("Widget/Game/CloudWidget")
export default class CloudWidget extends BaseWidget {
    @property([cc.Prefab])
    prefabs: cc.Prefab[] = [];

    protected start(): void {
        this._genCloud();
    }

    private _genCloud(){
        let idx = Math.floor(Math.random() * this.prefabs.length);
        let cloud = cc.instantiate(this.prefabs[idx]);
        cloud.setParent(this.node);
        cloud.setPosition(cc.v2(this.node.width * 0.5 + 500, -this.node.height * 0.5 + Math.random() * this.node.height));

        cc.tween(cloud)
        .by(10 + Math.random() * 5, {x: -(this.node.width + 1000)})
        .removeSelf()
        .start();

        this.scheduleOnce(this._genCloud.bind(this), Math.random() * 5 + 5);
    }
}